package com.example.appointment.repository;

import com.example.appointment.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface UserRepository extends JpaRepository<User, Long> {
    Optional<User> findByUsername(String username);
    boolean existsByUsername(String username);
    boolean existsByEmail(String email);
    
    @Modifying
    @Query("UPDATE User u SET u.name = ?2 WHERE u.id = ?1")
    int updateName(Long id, String name);
    
    @Query("SELECT u FROM User u WHERE u.id = ?1")
    Optional<User> findByIdWithDetails(Long id);
} 